package main

import (
	"log"
	"time"

	"github.com/micro/go-micro"
	"github.com/micro/go-micro/cmd"
	"wangkechun/micro-test2/hello_server/subscriber"
)

func main() {
	// New Service
	cmd.Init()
	service := micro.NewService(
		micro.Name("go.micro.api.hello"),
		micro.Version("latest"),
		micro.RegisterTTL(time.Minute),
		micro.RegisterInterval(time.Second*30),
	)

	// Register Handler
	// example.RegisterExampleHandler(service.Server(), new(handler.Example))

	// Register Struct as Subscriber
	err := service.Server().Subscribe(
		service.Server().NewSubscriber("topic.go.micro.srv.hello", new(subscriber.Example)),
	)
	if err != nil {
		log.Fatalln(err)
	}

	// Register Function as Subscriber
	err = service.Server().Subscribe(
		service.Server().NewSubscriber("topic.go.micro.srv.hello", subscriber.Handler),
	)
	if err != nil {
		log.Fatalln(err)
	}

	// Initialise service
	service.Init()

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
